package com.xiaohe66.web.domain.birth.value;

import com.xiaohe66.common.ex.BusinessException;
import com.xiaohe66.common.value.ErrorCodeEnum;
import com.xiaohe66.web.integration.domain.IntValue;
import lombok.EqualsAndHashCode;

/**
 * @author xiaohe
 * @since 2023.07.12 16:00
 */
@EqualsAndHashCode(callSuper = true)
public class BirthdayType extends IntValue {

    public static final BirthdayType CHINESE = new BirthdayType(0);
    public static final BirthdayType GREGORIAN = new BirthdayType(1);

    private BirthdayType(int value) {
        super(value);
    }

    public static BirthdayType valueOf(int value) {
        if (CHINESE.getValue() == value) {
            return CHINESE;

        } else if (GREGORIAN.getValue() == value) {
            return GREGORIAN;

        } else {
            throw new BusinessException(ErrorCodeEnum.PARAM_ILLEGAL);
        }
    }

    public String name() {
        return getValue() == CHINESE.getValue() ? "农历" : "公历";
    }

    @Override
    public String toString() {
        return "BirthdayType(" + getValue() + ")";
    }
}
